<template>
	<view>
		<navbar mode="normal" title="我的地址"></navbar>
		<view class="content" v-if="canshow">
			<uni-list>
				<uni-list-item v-for="(item,index) in addressList" :title="item.name + ' ' + item.phone" :note="item.address" link="" @click="update(item)" :rightText="item.id==user.addressId?'首地址':''"></uni-list-item>
				<uni-list-item title="新增地址" link="" @click="addAddress"></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList:[],
				canshow:false,
				user:{}
			};
		},
		onLoad() {
			this.user = this.$getNowUser()
			this.getList()
		},
		methods:{
			addAddress(){
				uni.navigateTo({
					url:"/pages/update-address/update-address?mode=0"
				})
			},
			update(item){
				uni.navigateTo({
					url:"/pages/update-address/update-address?mode=1&id="+item.id+"&name="+item.name+"&phone="+item.phone+"&address="+item.address
				})
			},
			getList(){
				var user = uni.getStorageSync("user")
				var vue = this
				this.$request("address/getOne",{userId:user.id},function(res){
					vue.addressList = res.data.data
					vue.canshow = true
				})
			}
		},
		onShow() {
			var vue = this
			vue.canshow = false
			setTimeout(function(){
				vue.user = vue.$getNowUser()
				vue.getList()
			},1)
		}
	}
</script>

<style lang="scss">

</style>
